package com.byq.mcpanus.model;

import org.springframework.ai.chat.messages.*;

public class MyMessage {
    String content;
    String imageBase64;
    MessageType type;
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getImageBase64() {
        return imageBase64;
    }

    public void setImageBase64(String imageBase64) {
        this.imageBase64 = imageBase64;
    }

    public MessageType getType() {
        return type;
    }

    public void setType(MessageType type) {
        this.type = type;
    }
    public Message toMessage(){
        if(type == MessageType.USER) {
            if (imageBase64 != null && !imageBase64.isEmpty()) {
                org.springframework.ai.model.Media media = org.springframework.ai.model.Media.builder()
                        .data(imageBase64)
                        .mimeType(org.springframework.util.MimeType.valueOf("image/jpeg"))
                        .build();
                return new UserMessage(content, java.util.List.of(media));
            } else {
                return new UserMessage(content);
            }
        }
        if(type == MessageType.SYSTEM)
            return new SystemMessage(content);
        if(type == MessageType.ASSISTANT)
            return new AssistantMessage(content);
        return null;
    }
    public void fromMessage(Message m){
       type = m.getMessageType();
       content = m.getText();
       imageBase64 = null;
       if (type == MessageType.USER && m instanceof UserMessage um) {
           if (um.getMedia() != null && !um.getMedia().isEmpty()) {
               org.springframework.ai.model.Media media = um.getMedia().get(0);
               imageBase64 = media.getData() != null ? media.getData().toString() : null;
           }
       }
    }


}
